﻿using ARchGL.Platform.FileServer;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.Collections.Generic;
using System.Text;
using WebApiClient;

namespace ARchGL.Platform.Jianwei
{
    /// <summary>
    /// 注册：实名制服务端接口
    /// </summary>
    public static class RealServerHttpRegistrar
    {
        public static IServiceCollection Register(IServiceCollection services, IConfigurationRoot appConfiguration)
        {
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            void config(HttpApiConfig c)
            {
                c.HttpHost = new Uri(appConfiguration["Jianwei:RealServerApi"]);
                c.GlobalFilters.Add(new RealServerDefaultHeaderAttribute(appConfiguration));
                c.FormatOptions.DateTimeFormat = DateTimeFormats.ISO8601_WithMillisecond;
            }

            services.AddHttpApi<IRealServerInfoApi>().ConfigureHttpApiConfig(config);

            return services;
        }
    }

    /// <summary>
    /// 注册：实名制终端接口
    /// </summary>
    public static class RealClientHttpRegistrar
    {
        public static IServiceCollection Register(IServiceCollection services, IConfigurationRoot appConfiguration)
        {
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            void config(HttpApiConfig c)
            {
                c.HttpHost = new Uri(appConfiguration["Jianwei:RealClientApi"]);
                c.GlobalFilters.Add(new RealClientDefaultHeaderAttribute(appConfiguration));
                c.FormatOptions.DateTimeFormat = DateTimeFormats.ISO8601_WithMillisecond;
                //c.GlobalFilters.Add(new ServiceTokenAttribute());
            }

            services.AddHttpApi<IRealClientInfoApi>().ConfigureHttpApiConfig(config);

            return services;
        }
    }
}
